package com.yanqu.road.server.logic.activity.condition.businessdepart;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ActivityValueParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;

import java.math.BigInteger;

public class BusinessDepartActiveCondition extends BaseActivityCondition {
    public BusinessDepartActiveCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ActivityValueParamArgs args = (ActivityValueParamArgs) object;
        //判断活动是否一致
        if (args.getActivityId() != this.getActivityConditionInfo().getActivityId()) {
            return;
        }
        //判断天数是否符合
        if (getValue().compareTo(BigInteger.valueOf(args.getValue())) < 0) {
            setValue(BigInteger.valueOf(args.getValue()));
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.BusinessDepartActiveTask.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.BusinessDepartActiveTask.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        if (getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0) {
            return true;
        }
        return false;
    }
}
